import random
import time


class Utils:

    @staticmethod
    def random_wait(min_sec: int, max_sec: int):
        wait_sec = random.randint(min_sec, max_sec)
        time.sleep(wait_sec)

    @staticmethod
    def random_num(size=17):
        text = ""
        for i in range(size):
            text = text + str(random.randint(0, 9))
        return text

    @staticmethod
    def keyword_fq_from_text(keywords: list, text: str):
        """
        计算一组关键词在一段文本出现的频次
        :param keywords: 关键词组
        :param text: 文本
        :return:
        """
        fqs = []
        for keyword in keywords:
            cnt = text.count(keyword)
            if cnt > 0:
                fqs.append({"keyword": keyword, "value": cnt})
        return fqs
